﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Rose.Models;

namespace Rose.Helper
{
    public class ListHelpModel
    {
        private  Database_RoseEntities db = new Database_RoseEntities();
        private Database_MovieEntities movie_db = new Database_MovieEntities();
        public  SelectList GetYearList(int year)
        {
            List<SelectListItem> yearlist = new List<SelectListItem>();
            for (int i = 1880; i <= (DateTime.Now).Year; i++)
            {
                yearlist.Add(new SelectListItem() { Value = i.ToString(), Text = i.ToString() });
            }
            return new SelectList(yearlist, "Value", "Text",year);
         
        }


  

        public  SelectList GetGenderList(string gender)
        {
            List<SelectListItem> genderlist = new List<SelectListItem>();
            genderlist.Add(new SelectListItem() { Value = "M", Text = "男" });
            genderlist.Add(new SelectListItem() { Value = "F", Text = "女" });
            return new SelectList(genderlist,"Value","Text",gender);
        }




        public  List<AddressModel> GetProvinceList()
        {
            List<AddressModel> returnModel = new List<AddressModel>();
            List<City> ProvinceList = db.Cities.Where(c => c.ParentId == 0).ToList();
            foreach (City Province in ProvinceList)
            {
                returnModel.Add(new AddressModel() { Value = Province.CityId, Text = Province.Name });
            }
            return returnModel;
        }

        public  List<AddressModel> GetCityList(int provinceId)
        {
            List<AddressModel> returnModel = new List<AddressModel>();
            List<City> CityList = db.Cities.Where(c => c.ParentId == provinceId).ToList();
            foreach (City Province in CityList)
            {
                returnModel.Add(new AddressModel() { Value = Province.CityId, Text = Province.Name });
            }
            return returnModel;
        }

        public  List<AddressModel> GetCollege(int schoolId)
        {
            List<AddressModel> returnModel = new List<AddressModel>();

            var relations = db.School_Colleges.Where(c => c.School == schoolId);
            foreach (var relation in relations)
            {
                College college = db.Colleges.Where(c => c.CollegeId == relation.College).FirstOrDefault();
                if (college == null)
                    continue;
                returnModel.Add(new AddressModel() { Value = college.CollegeId, Text = college.Name });
            }
            returnModel.Add(new AddressModel() { Value = -1, Text = "其他" });
            return returnModel;
        }

        public  SelectList GetCollegeSelectList(int schoolId) 
        {
            List<SelectListItem> returnModel = new List<SelectListItem>();
            var relations = db.School_Colleges.Where(c => c.School == schoolId);
            foreach (var relation in relations)
            {
                College college = db.Colleges.Where(c => c.CollegeId == relation.College).FirstOrDefault();
                if (college == null)
                    continue;
                returnModel.Add(new SelectListItem() { Value = college.CollegeId.ToString(), Text = college.Name });
            }
            return new SelectList(returnModel, "Value", "Text");

        }

        //public  List<AddressModel> GetMojor(int schoolId, int collegeId)
        //{
        //    List<AddressModel> returnModel = new List<AddressModel>();

        //    var relations = db.School_College_Majors.Where(c => c.SchoolId == schoolId && c.CollegeId == collegeId);
        //    foreach (var relation in relations)
        //    {
        //        Major major = db.Majors.Where(c => c.MajorId == relation.MajorId).FirstOrDefault();
        //        if (major == null)
        //            continue;
        //        returnModel.Add(new AddressModel() { Value = major.MajorId, Text = major.Name });
        //    }

        //    returnModel.Add(new AddressModel() { Value = -1, Text = "其他" });
        //    return returnModel;

        //}


        public  SelectList GetAlbumList(string selfId)
        {
            var model = db.Albums.Where(c => c.UserId == selfId);
            List<SelectListItem> albumlist = new List<SelectListItem>();
            foreach (var album in model)
            {
                albumlist.Add(new SelectListItem() { Value = album.Id.ToString(), Text = album.Title });
            }

            return new SelectList(albumlist, "Value", "Text");
        }


        
        public SelectList GetWuHanCamera(int cameraId = 1821)
        {
            var model = movie_db.Cameras.OrderBy(c => c.CameraId);
            List<SelectListItem> returnModel = new List<SelectListItem>();
            foreach (var item in model)
            {
                returnModel.Add(new SelectListItem() { Value = item.CameraId.ToString(), Text = item.CameraName });
            }

            return new SelectList(returnModel, "Value", "Text",cameraId);
        }

       
        
       
    }
}